#include<stdio.h>
int t;
char s[10010];
int main()
{
  int i,j;
  long int sum;
  char c;
  scanf("%d",&t);
  scanf("%c",&c);
  for (i=0;i<t;i++)
    {
	  sum=0;
	  scanf("%s",s);
	  for (j=0;s[j]!=0;j++)
	    sum=sum+s[j]-'0';
	  if (sum%3==0) printf("YES\n");else printf("NO\n");
	  scanf("%c",&c);
	}
  return 0;
}